package demo02;
//寻找旋转排序数组最小值
class Solution {
    public int findMin(int[] nums) {
        int left = 0;
        int right = nums.length - 1;
        int n = nums.length - 1;
        while(left < right){
            int mid = left + (right - left) / 2;
            if(nums[mid] > nums[n]) left = mid + 1;
            if(nums[mid] <= nums[n]) right = mid;
        }
        return nums[left];
    }
}

//方法二
//class Solution {
//    public int findMin(int[] nums) {
//        int left = 0;
//        int right = nums.length - 1;
//        int n = 0;
//        //没有发生旋转
//        if(nums[0] < nums[right]) return nums[0];
//        //已旋转
//        while(left < right){
//            int mid = left + (right - left) / 2;
//            if(nums[mid] > nums[n]) left = mid + 1;
//            if(nums[mid] <= nums[n]) right = mid;
//        }
//        return nums[left];
//
//    }
//}